//退货通知单 及 退货申请 
public without sharing class ReturnOrderListController{

    public String backId {get;private set;}
    public Boolean isErr {get;private set;} 
    public String msg {get;set;} 

    public String dataJson {get;set;}
    public String searchJson {get;set;}
    public String saveJson {get;set;}

    public Boolean isSuccess {get;private set;}
    public String companyMap {get;set;}
    public ReturnOrder__c roc ;//退货申请

    public ReturnRequisition__c rr ;//退货通知单

    public Boolean isRR {get; private set;}

    public ReturnOrderListController(){


        backId = System.currentPageReference().getParameters().get('id');
        isRR = false;
    
    }

    public void init(){
        try{
            if(String.isBlank(backId)  )throw new DmlException('页面打开错误!');
                getCompanyMap();

            Map<String,Object> dataMap = new Map<String,Object>();
            if(Id.valueOf(backId).getSObjectType() == ReturnOrder__c.SObjectType ){
                //退货申请
                 roc = [select Id,Account__r.AccountNumber,Approve_Status__c from ReturnOrder__c where Id=:backId];

                if(roc.Approve_Status__c == '审批中' || roc.Approve_Status__c == '审批通过'  ) throw new DmlException ('退货申请'+roc.Approve_Status__c + ',不能修改!');
                
                if(roc.Account__r.AccountNumber == null) throw new DmlException('请联系管理员维护客户编号!');

                dataMap.put('detail', getReturnList());
                dataMap.put('search', getReturnListFromRequisition());

            }else if(Id.valueOf(backId).getSObjectType() == ReturnRequisition__c.SObjectType){

                 isRR = true ;
                //退货通知单 
                rr = [select Id,Account__c,Account__r.AccountNumber from ReturnRequisition__c where Id=:backId];
                //可以从NC出库中选择
                dataMap.put('detail', getRequisitionList());



            }

            dataJson = EncodingUtil.urlEncode(JSON.serialize(dataMap), 'UTF-8');
        }catch(Exception e ){
            isErr = true;
            ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR ,e.getMessage()));
        }


    }
    
    public void setNil(){
        msg = '';
        dataJson = '[]';
        searchJson = '';
        isSuccess = false;

    }
    public void getCompanyMap(){

      companyMap  =  EncodingUtil.urlEncode(JSON.serialize(ImportObject.getPicklistValues('Contract__c','Corpcode__c',true)), 'UTF-8');
    }
    //获取退货明细
    public List<ReturnOrderListBean> getReturnList(){
        List<ReturnOrderListBean> rbL = new List<ReturnOrderListBean>();
        for(ReturnOrderList__c ro : [select Id,ReturnRequisitionList__c,Account__r.Name,Product__c,Product__r.ProductName__c,Product__r.Name ,Product__r.NCCode__c,Product__r.Model__c,
            BatchNumber__c,ExpirationDate__c,ProductLine__c,dbizdate__c,Note__c,Nnum__c,Account__c,NCvpzwh__c,RefundNumber__c,DetailPk__c,
            Outdoor__c,Product__r.Spec__c,Product__r.SerialNo__c,Product__r.Brand__c,Product__r.NCvpzwh__c,Product__r.Unit__c
         from ReturnOrderList__c where ReturnOrderList__c =:backId ]){

        
            rbL.add(new ReturnOrderListBean(ro));

        }
        return rbL;
        
    }

    //检索 退货申请 从 退货通知单明细中选择 : 条件:客户相等  关联的退货通知单明细为空 
    public List<ReturnOrderListBean> getReturnListFromRequisition(){

        List<ReturnOrderListBean> rbL = new List<ReturnOrderListBean>();
        for (ReturnRequisitionList__c r  : [select ReturnRequisition__r.Name , Id ,Product__r.ProductName__c, Nnum__c,RefundNumber__c,Outdoor__c ,BatchNumber__c ,Product__r.Spec__c,Product__r.SerialNo__c,
            Product__r.NCCode__c,Product__r.Brand__c , Product__r.NCvpzwh__c,Product__r.Model__c,Product__r.Unit__c,dbizdate__c,ExpirationDate__c,Note__c,DetailPk__c 
            from ReturnRequisitionList__c where  Done__c != true  and ReturnRequisition__r.Account__c =: roc.Account__c ]) {
            
            rbL.add( new  ReturnOrderListBean(r)) ;

        }
        return rbL;

    }
    public List<ReturnOrderListBean> getRequisitionList(){

        List<ReturnOrderListBean> rbL = new List<ReturnOrderListBean>();
        for (ReturnRequisitionList__c r  : [select Id ,Product__r.ProductName__c, Nnum__c,RefundNumber__c ,BatchNumber__c ,Product__r.Spec__c,Product__r.SerialNo__c,
            Product__r.NCCode__c,Product__r.Brand__c , Product__r.NCvpzwh__c,Product__r.Model__c,Product__r.Unit__c,Outdoor__c,dbizdate__c,ExpirationDate__c,Note__c,DetailPk__c 
            from ReturnRequisitionList__c where  ReturnRequisition__c  =: rr.Id  ]) {
            rbL.add( new  ReturnOrderListBean(r)) ;

        }
        return rbL;

    }


    public void search (){

        msg = '';
        dataJson = '[]';
        Map<String,Object> searchMap = (Map<String,Object>) JSON.deserializeUntyped(EncodingUtil.urlDecode(searchJson, 'UTF-8'));


        String sql = getSql();
        if(searchMap.get('invname') != null 
        && String.isBlank(String.valueOf(searchMap.get('invname')))== false ) sql += ' and  ic.invname like \'%'+String.valueOf(searchMap.get('invname')).trim()+'%\'';

        if(searchMap.get('unitcode') != null 
        && String.isBlank(String.valueOf(searchMap.get('unitcode')))== false ) sql += ' and  cp.unitcode =\''+String.valueOf(searchMap.get('unitcode')).trim()+'\'';

        if(searchMap.get('invcode') != null 
        && String.isBlank(String.valueOf(searchMap.get('invcode')))== false ) sql += ' and  ic.invcode =\''+String.valueOf(searchMap.get('invcode')).trim()+'\'';

        if(searchMap.get('invpinpai') != null 
        && String.isBlank(String.valueOf(searchMap.get('invpinpai')))== false ) sql += ' and  ic.invpinpai like \'%'+String.valueOf(searchMap.get('invpinpai')).trim()+'%\'';

        if(searchMap.get('dbizdate_begin') != null 
        && String.isBlank(String.valueOf(searchMap.get('dbizdate_begin')))== false ) sql += ' and g.dbilldate >= \''+String.valueOf(searchMap.get('dbizdate_begin')).trim()+'\'';

        if(searchMap.get('dbizdate_end') != null 
        && String.isBlank(String.valueOf(searchMap.get('dbizdate_end')))== false ) sql += ' and g.dbilldate <= \''+String.valueOf(searchMap.get('dbizdate_end')).trim()+'\'';

        if(searchMap.get('dbillcode') != null 
        && String.isBlank(String.valueOf(searchMap.get('dbillcode')))== false ) sql += ' and g.vbillcode = \''+String.valueOf(searchMap.get('dbillcode')).trim()+'\'';

        if(searchMap.get('invspec') != null 
        && String.isBlank(String.valueOf(searchMap.get('invspec')))== false ) sql += ' and ic.invspec like \'%'+String.valueOf(searchMap.get('invspec')).trim()+'%\'';

        if(searchMap.get('invmodel') != null 
        && String.isBlank(String.valueOf(searchMap.get('invmodel')))== false ) sql += 'and ic.invtype like  \'%'+String.valueOf(searchMap.get('invmodel')).trim()+'%\'';
        
        if(searchMap.get('serialNo') != null 
        && String.isBlank(String.valueOf(searchMap.get('serialNo')))== false ) sql += ' and minv.invmnecode = \''+String.valueOf(searchMap.get('serialNo')).trim()+'\'';
       
        if(searchMap.get('batchNumber') != null 
        && String.isBlank(String.valueOf(searchMap.get('batchNumber')))== false ) sql += ' and gb.vbatchcode like \'%'+String.valueOf(searchMap.get('batchNumber')).trim()+'%\'';
       
         String url = Label.queryResposityURL;

        sql = '{"data":" '+ sql +'"}';
        System.debug(sql);
        //请求

        HttpRequest req = new HttpRequest();
        req.setBody(sql);
        req.setMethod('POST');
        req.setHeader('Content-Type','text/plain');
        req.setEndpoint(url);
        HttpResponse res = Utils.postRequest(req, 2);
      ///返回结果处理
        if (res.getStatusCode() == 200) {
          System.debug(res.getBody());
            Map<String,Object> r = null;
              //如果是测试
                if(Test.isRunningTest()){
                  Map<String,Object>  resBody= new Map<String,Object>();
                  resBody.put('code','0');
                  resBody.put('result','{"result_msg":"查询成功！","result":1,"data":[{"dbilldate":"2018-12-11","corpcode":"MKSY","dbillcode":"XC02181240020","invcode":"110100100025","vbatchcode":"0718071","nnum":10,"dproducedate":"2018-07-18","dr":0,"invpinpai":"迈克生物","invname":"天门冬氨酸氨基转移酶测定试剂盒（天门冬氨酸底物法）","vdotechnics":"2022-02-15","custname":"广安市人民医院","vapprovalnum":"川械注准20172400051","custcode":"604479","invdm":"CH0101202","dvalidate":"2020-07-18","zdkh":"广安市人民医院","nshouldoutnum":10,"jldw":"盒","invtype":"AST：7170双","invspec":"试剂1 60mL×3 试剂2 45mL×1"}]}');
                    r =  resBody;
                }else{
                  r= (Map<String,Object> ) JSON.deserializeUntyped(res.getBody());
                }
          if(r.get('code') == 0 || r.get('code') == '0'){
             Map<String,Object> rs = (Map<String,Object>) JSON.deserializeUntyped(((String)r.get('result')));
              if( rs.get('result') == 1 ){
                    Set<String> nccodes = new Set<String>();
                    List<ReturnOrderListBean> rlist = new List<ReturnOrderListBean>();
                    Set<String> detailpks  = new Set<String>();


                    List<Object> datas = (List<Object>)rs.get('data');
                    for(Object ob :datas){
                        Map<String,Object> m = (Map<String,Object>) ob;
                        nccodes.add(String.valueOf(m.get('invcode')));
                        rlist.add(new ReturnOrderListBean(m)) ;
                        detailpks.add(String.valueOf(m.get('cgeneralbid')));

                    }
                    System.debug(detailpks);
                    detailpks.clear();
                    //排除已经选择过的出库明细
                    if(isRR){

                        for(ReturnRequisitionList__c rl  :[select  DetailPk__c from  ReturnRequisitionList__c where DetailPk__c in:detailpks   ] ) {
                           
                            detailpks.add(rl.DetailPk__c );
                        }
                    }
                   

                    Map<String,Product__c> productMap =  ImportObject.getProudctMap(nccodes);
                    for(Integer i = rlist.size() -1 ; i >=0 ; i -- ){
                        ReturnOrderListBean ro = rlist.get(i);
                        Product__c  p = productMap.get(ro.nccode);
                        if(p != null )ro.productId = p.Id;
                        if(detailpks.contains(ro.detailpk)){
                            rlist.remove(i);
                        }
                    }
                
                
                    dataJson = EncodingUtil.urlEncode(JSON.serialize(rlist), 'UTF-8') ;

               }else{
                 msg = String.valueOf(rs.get('result_msg'));
               }

          //resJson = EncodingUtil.urlEncode(res.getBody(), 'UTF-8') ;
        }else{
          msg = '查询出库单数据失败 : '+String.valueOf(r.get('msg'));
           ///System.debug(res.toString());
          //resJson = EncodingUtil.urlEncode('{"result":"","code":"1","msg":"接口错误,查询失败!"}','UTF-8');
        }

      }else{
        msg = '查询出库单数据失败 : '+res.getBody();
      }

           

    }



    // public void searchAccount(){

    //     Map<String,Object> searchMap = (Map<String,Object>) JSON.deserializeUntyped(EncodingUtil.urlDecode(searchJson, 'UTF-8'));
    //     List<Object> tmp = new  List<Object>();
    //     String sql = ' select Id , Name from Account where RecordType.DeveloperName != \'Maccura\'  ';

    //     if(String.isNotBlank((String)searchMap.get('Name')) )sql += ' and Name like \'%'+searchMap.get('Name')+'%\' ';
    //     sql += ' limit 20 ';

    //     for (Account acc  : Database.query(sql) ) {
    //         tmp.add(acc.getPopulatedFieldsAsMap());
    //     }
    //     dataJson = EncodingUtil.urlEncode(JSON.serialize(tmp), 'UTF-8') ;

    // }

    public void save(){

        msg = '';
        List<Object> roL = (List<Object>) JSON.deserializeUntyped(EncodingUtil.urlDecode(saveJson, 'UTF-8'));
        

        Set<String> nccodes = new Set<String>();
        for(Object o : roL){

            Map<String,Object> mo = (Map<String,Object>) o;
            nccodes.add(getStringValue(mo.get('nccode')));

        }
        Map<String,Product__c> prodMap = ImportObject.getProudctMap(nccodes);
        List<ReturnOrderList__c> nroList  = new List<ReturnOrderList__c>();
         List<ReturnRequisitionList__c> rrList   = new List<ReturnRequisitionList__c>();

        Set<String> proset = new Set<String>();
        for(Object o : roL){

            Map<String,Object> mo = (Map<String,Object>) o;
            ReturnOrderList__c ro = new ReturnOrderList__c();
            Product__c p = prodMap.get(getStringValue(mo.get('nccode')));
            if( p  == null ){

                msg = getStringValue(mo.get('invname')) +':'+getStringValue(mo.get('nccode')) +'未在系统中匹配到产品 !请联系管理员维护!';
                return;
            }
            ro.Product__c = p.Id;
            proset.add(p.Id);
            ro.ReturnOrderList__c = backId; 
            ro.ExpirationDate__c = getDateValue(mo.get('exprirateDate')); 
            ro.BatchNumber__c = getStringValue(mo.get('batchNumber'));
            ro.Outdoor__c = getStringValue(mo.get('outdoor'));
            ro.dbizdate__c = getDateValue(mo.get('dbizdate'));
            ro.Nnum__c = getDecimalValue(mo.get('nnum'));
            ro.RefundNumber__c = getDecimalValue(mo.get('returnNum'));
            ro.Note__c = getStringValue(mo.get('note'));
            ro.DetailPk__c = getStringValue(mo.get('detailpk'));
            ro.ReturnRequisitionList__c  = getStringValue(mo.get('rrId')); 
            ro.Account__c = getStringValue(mo.get('terminalId'));

            nroList.add(ro);

            if(isRR){

                ReturnRequisitionList__c rrL = new ReturnRequisitionList__c();
                rrL.Product__c = p.Id;
                rrL.BatchNumber__c = ro.BatchNumber__c;
                rrL.ExpirationDate__c = ro.ExpirationDate__c;
                 //rrL.ProductLine__c
                 rrL.Outdoor__c = ro.Outdoor__c;
                 rrL.DetailPk__c = ro.DetailPk__c;
                 rrL.dbizdate__c = ro.dbizdate__c;
                 rrL.Note__c = ro.Note__c;
                 rrL.Nnum__c = ro.Nnum__c;
                 rrL.RefundNumber__c = ro.RefundNumber__c;
                 rrL.ReturnRequisition__c = rr.Id;

                 rrList.add(rrL);
            }
            

        }
        Set<String> nCs  = new Set<String>();
        for(Product__c p : [select Id,NCCode__c from Product__c where Id in:proset and ProductStructure__c = null ]){
            nCs.add(p.NCCode__c);
           
        }
        if(!isRR &&  !nCs.isEmpty()){

            msg = '存货编码为'+String.join( new List<String>(nCs), ',')+'的产品无产品结构 请联系 管理员添加产品结构';
            return;
        }

        Savepoint sp = Database.setSavepoint();
        try {
            if(isRR){

                 delete  [select Id from ReturnRequisitionList__c  where  ReturnRequisition__c =: rr.Id ];

                if(rrList.size() > 0) insert rrList;




            }else{
                   List<ReturnOrderList__c> derl = [select Id from ReturnOrderList__c  where  ReturnOrderList__c =: backId];

                   
                if(derl.size() > 0) delete derl;

                if(nroList.size() > 0) insert nroList;

                // List<ReturnRequisitionList__c>tmp = new List<ReturnRequisitionList__c>();
                // for ( ReturnOrderList__c rr: nroList ) {

                //     ReturnRequisitionList__c ro = new ReturnRequisitionList__c();
                //     ro.Id = rr.ReturnRequisitionList__c ;
                //     ro.ReturnOrderList__c = ro.Id;



                //     tmp.add(ro);

                // }
                // if(!tmp.isEmpty())update tmp;
            }
         
            msg = '保存成功!';
            isSuccess= true; 

        }
        catch (Exception e) {
            Database.rollback(sp);
            msg = '保存失败!' + e.getMessage() + e.getStackTraceString();
            isSuccess = false;

        }
        

    }
    private Date getDateValue(Object o ){
        String s = getStringValue(o);
        if(s == null || s=='') return null;
        return Date.valueOf(s);
    }
    private String  getStringValue(Object o){
        if(o == null) return null;
        return String.valueOf(o).trim();
    }
    private Decimal getDecimalValue(Object o){
        String s = getStringValue(o);
        if(s == null || s=='') return null;
        return Decimal.valueOf(s);
    }
    private String getSql(){

        System.debug(isRR);
        String accNumber = isRR ?  rr.Account__r.AccountNumber :roc.Account__r.AccountNumber ;

        return 'select '+

                'nvl(cp1.unitshortname,cb.custname) custname, '+
                'nvl(cp1.unitcode,cb.custcode) Custcode, '+

                'cp.unitcode corpcode, '+
                'cp.unitshortname unitname ,'+

              //  ' cb.custname custname, '+
               // ' cb.custcode Custcode, '+
                'gb.cgeneralbid, '+

                ' g.dbilldate dbilldate, '+
                '  br.rdname sflx, '+
                '  ic.invpinpai invpinpai, '+
                ' ic.invname invname, '+
                ' ic.invcode invcode, '+
                ' minv.invmnecode invdm, '+
                ' gb.vbatchcode Vbatchcode, '+
                ' be.dproducedate dproducedate, '+
                ' be.dvalidate dvalidate, '+
                ' case '+
                '   when gb.nshouldoutnum is null then '+
                '    0.00 '+
                '   else '+
                '    gb.nshouldoutnum '+
                ' end nshouldoutnum, '+
                ' case '+
                '   when gb.noutnum is null then '+
                '    0.00 '+
                '   else '+
                '    gb.noutnum '+
                ' end nnum, '+
                ' g.vbillcode dbillcode, '+
                ' g.vuserdef7 zdkh, '+
                ' ic.invtype invtype, '+
                ' ic.invspec invspec, '+
                ' mc.measname jldw, '+
                'minv.vdotechnics vdotechnics, '+
                'minv.vapprovalnum vapprovalnum, '+
                'case when g.dr>gb.dr then g.dr else gb.dr end dr '+
                '  from ic_general_h g '+
                '  left join ic_general_b gb on g.cgeneralhid = gb.cgeneralhid '+
                '  left join bd_corp cp on cp.pk_corp = gb.pk_corp '+
                '  left join bd_cumandoc cm on cm.pk_cumandoc = g.ccustomerid '+
                '  left join bd_cubasdoc cb on cb.pk_cubasdoc = cm.pk_cubasdoc '+
                '  left join bd_rdcl br on br.pk_rdcl = g.cdispatcherid '+
                '  left join bd_invbasdoc ic on ic.pk_invbasdoc = gb.cinvbasid  '+
                '  left join scm_batchcode be on be.vbatchcode = gb.vbatchcode '+
                '                            and be.pk_invbasdoc = gb.cinvbasid '+
                '                            and nvl(be.dr, 0) = 0 '+
                '  left join bd_measdoc mc on mc.pk_measdoc = ic.pk_measdoc  '+
                '  left join med_invbasdoc minv on minv.pk_invbasdoc = ic.pk_invbasdoc '+
                
                'left join bd_corp cp1  '+
                'on cp1.pk_corp = g.cothercorpid '+
                //' where gb.dr = 0 and gb.dr=0  and  cb.custcode=\'604479\' and g.cbilltypecode in  (\'42\',\'4B\',\'4C\',\'4H\',\'4I\',\'4Y\') ';
               ' where gb.dr = 0 and gb.dr=0  '+
                //'and  nvl(cp1.unitcode,cb.custcode) =\'CQZT\' ';
                //'and  nvl(cp1.unitcode,cb.custcode) =\''+roc.Account__r.AccountNumber+'\' ';
                ' and  (nvl(cp1.unitcode,cb.custcode) =\''+accNumber+'\'  or g.vuserdef7=(select custname from bd_cubasdoc where custcode=\''+accNumber+'\' )) ';

    }




    public class ReturnOrderListBean{
        public String productId ;//产品ID 
        public String invname {get;set;}//存货名称
        public Decimal nnum {get;set;}//实发数量
        public String nccode ;//存货编码
        public Decimal returnNum {get;set;}//退货数量
        public String  batchNumber {get;set;}//批号
        public String  spec {get;set;}//型号
        public String  serialNo {get;set;}//货号
        public String  brand {get;set;}//品牌
        public String  ncvpzwh {get;set;}//批准文号
        public String outdoor ;//出库单号
        public String detailpk ; //出库单明细pk ;
        public String model ; 
        public String unit ;//单位
        public String dbizdate ; //出库日期
        public String exprirateDate; //失效期
        public String note;
        public String sflx ;//收发类别
        public String company ;//开票公司
        public String rrId ;//退货通知单Id 

        public String terminalId ; 
        public String terminal;

        public String reqName;


        public ReturnOrderListBean(ReturnOrderList__c ro ){
            productId = ro.Product__c ; 
            invname = ro.Product__r.ProductName__c == null ? ro.Product__r.Name : ro.Product__r.ProductName__c;
            nnum = ro.Nnum__c;
            returnNum = ro.RefundNumber__c;
            batchnumber = ro.BatchNumber__c;
            spec = ro.Product__r.Spec__c;
            serialNo = ro.Product__r.SerialNo__c;
            nccode= ro.Product__r.NCCode__c;
            brand = ro.Product__r.Brand__c;
            ncvpzwh = ro.Product__r.NCvpzwh__c;
            outdoor = ro.Outdoor__c;
            model = ro.Product__r.Model__c;
            unit = ro.Product__r.Unit__c;
            dbizdate = ro.dbizdate__c == null ? '':ro.dbizdate__c.format() ;
            exprirateDate = ro.ExpirationDate__c == null ? '' : ro.ExpirationDate__c.format();
            note = ro.Note__c;
            detailpk = ro.DetailPk__c;
            rrId = ro.ReturnRequisitionList__c  ;
            terminal = ro.Account__r.Name ;
            terminalId = ro.Account__c;

        }

        public ReturnOrderListBean(Map<String,Object> ro ){
            invname = getStringValue(ro.get('invname'));
            nnum = getDecimalValue(ro.get('nnum'));
            //returnNum = getDecimalValue(ro.get(''));
            batchnumber = getStringValue(ro.get('vbatchcode'));
            nccode = getStringValue(ro.get('invcode'));
            spec = getStringValue(ro.get('invspec'));
            serialNo = getStringValue(ro.get('invdm'));
            brand = getStringValue(ro.get('invpinpai'));
            ncvpzwh = getStringValue(ro.get('vapprovalnum'));
            outdoor = getStringValue(ro.get('dbillcode'));
            model = getStringValue(ro.get('invtype'));
             unit = getStringValue(ro.get('jldw'));
            dbizdate = getStringValue(ro.get('dbilldate'));
            exprirateDate = getStringValue(ro.get('dvalidate'));
            sflx = getStringValue(ro.get('sflx'));
            company = getStringValue(ro.get('unitname'));
            detailpk = getStringValue(ro.get('cgeneralbid'));

        }

         public ReturnOrderListBean(ReturnRequisitionList__c ro ){
            productId = ro.Product__c ; 
            invname = ro.Product__r.ProductName__c == null ? ro.Product__r.Name : ro.Product__r.ProductName__c;
            nnum = ro.Nnum__c;
            returnNum = ro.RefundNumber__c;
            batchnumber = ro.BatchNumber__c;
            spec = ro.Product__r.Spec__c;
            serialNo = ro.Product__r.SerialNo__c;
            nccode= ro.Product__r.NCCode__c;
            brand = ro.Product__r.Brand__c;
            ncvpzwh = ro.Product__r.NCvpzwh__c;
            outdoor = ro.Outdoor__c;
            model = ro.Product__r.Model__c;
            unit = ro.Product__r.Unit__c;
             dbizdate = ro.dbizdate__c == null ? '':ro.dbizdate__c.format() ;
            exprirateDate = ro.ExpirationDate__c == null ? '' : ro.ExpirationDate__c.format();
            note = ro.Note__c;
            detailpk = ro.DetailPk__c;
            rrId = ro.Id   ;
            reqName = ro.ReturnRequisition__r.Name;

        }

        private String getStringValue(Object o){
            if(o == null) return null;

            return String.valueOf(o).trim();
        }
        private Decimal getDecimalValue(Object o){
            String s = getStringValue(o);
            if(s == null || s == '')return null;
            return Decimal.valueOf(s);
        }


    }
}